
#include "tool.h"

QString fun(QString insertString)
{

}


int is_valid_ip(QString insert)
{
    char*  ip;
    QByteArray change_ba = insert.toLatin1(); // must
    ip = change_ba.data();

    int section = 0;  //每一节的十进制值
    int dot = 0;       //几个点分隔符
    int last = -1;     //每一节中上一个字符
    while(*ip)
    {
        if(*ip == '.')
        {
            dot++;
            if(dot > 3)
            {
                return 0;
            }
            if(section >= 0 && section <=255)
            {
                section = 0;
            }else{
                return 0;
            }
        }else if(*ip >= '0' && *ip <= '9')
        {
            section = section * 10 + *ip - '0';
            if(last == '0')
            {
                return 0;
            }
        }else{
            return 0;
        }
        last = *ip;
        ip++;
    }

    if(section >= 0 && section <=255)
    {
        if(3 == dot)
        {
        section = 0;
        return 0;
      }
    }
    return 1;
}
